package com.project.controller;


import com.github.pagehelper.PageInfo;
import com.project.entity.RestPOJO;
import com.project.entity.Stall;
import com.project.service.AdminStallService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@RestController
public class AdminStallController {

    @Autowired
    private AdminStallService adminStallService;

    @ApiOperation(
            value = "管理员搜索所有车位",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="currentPage",value="当前页",required=true),
            @ApiImplicitParam(paramType="query",name="pageSize",value="每页显示的条目数",required=true)
    })

    @RequestMapping("/selAllStall")
    public RestPOJO selAllStall(Integer currentPage,Integer pageSize){
        RestPOJO restPOJO = new RestPOJO();
        PageInfo<Stall> stalls = adminStallService.selAllStall(currentPage,pageSize);
        if(stalls != null && stalls.getList().size() > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("查询成功");
            restPOJO.setData(stalls);
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("查询失败");
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "查询符合条件的所有车位信息",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="keyWord",value="查询条件的关键字",required=true),
            @ApiImplicitParam(paramType="query",name="currentPage",value="当前页",required=true),
            @ApiImplicitParam(paramType="query",name="pageSize",value="每页显示的条目数",required=true)
    })

    @RequestMapping("/selConditionStall")
    public RestPOJO selConditionStall(String keyWord,Integer currentPage,Integer pageSize){
        RestPOJO restPOJO = new RestPOJO();
        PageInfo<Stall> stalls = adminStallService.selConditionStall(keyWord,currentPage,pageSize);
        if(stalls != null && stalls.getList().size() > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("查询成功");
            restPOJO.setData(stalls);
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("查询失败");
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "冻结选中的车位集合",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明

    @RequestMapping("/delStall")
    public RestPOJO delStall(@RequestBody  Object[] ids){
        RestPOJO restPOJO = new RestPOJO();
        Integer delCount = adminStallService.delStall(ids);
        if(delCount > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("删除成功");
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("删除失败");
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "恢复选中的车位集合为正常状态",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明

    @RequestMapping("/recoverStall")
    public RestPOJO recoverStall(@RequestBody  Object[] ids){
        RestPOJO restPOJO = new RestPOJO();
        Integer recoverCount = adminStallService.recoverStall(ids);
        if(recoverCount > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("恢复成功");
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("恢复失败");
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "恢复正常状态选中的车位",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="path",name="id",value="选中用户的id",required=true)
    })


    @RequestMapping("/delOneStall/{id}")
    public RestPOJO delOneStall(@PathVariable("id") Integer id){
        RestPOJO restPOJO = new RestPOJO();
        Integer delOneCount = adminStallService.delOneStall(id);
        if(delOneCount > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("删除成功");
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("删除失败");
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "恢复正常状态选中的车位",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="path",name="id",value="选中用户的id",required=true)
    })

    @RequestMapping("/recoverOneStall/{id}")
    public RestPOJO recoverOneStall(@PathVariable("id") Integer id){
        RestPOJO restPOJO = new RestPOJO();
        Integer recoverOneCount = adminStallService.recoverOneStall(id);
        if(recoverOneCount > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("恢复成功");
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("恢复失败");
        }
        return restPOJO;
    }


}
